package servlet;

import dao.GoodsDao;
import pojo.Goods;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author konley
 * @date 2020-06-12 12:10
 */
@WebServlet("/FindCommServlet")
public class FindCommServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String m = request.getParameter("m");
        System.out.println("m = " + m);
        try {
            if(m.equals("findList")){   //请求下拉列表
                String comm = request.getParameter("comm");
                System.out.println("comm = " + comm);
                List<Goods> list = new GoodsDao().getListByName(comm);
                request.setAttribute("list", list);
                request.getRequestDispatcher("/list.jsp").forward(request,response);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
